package app

import (
	"go.uber.org/fx"
	"os"
	"strings"
)

type Config struct {
	// NatsServers is a list of NATS servers to connect to.
	NatsServers []string
	AppPort     string
	Environment string
	RpcSecret   string
}

func (c *Config) BuildFromEnv() {
	c.NatsServers = strings.Split(os.Getenv("NATS_SERVERS"), ",")
	c.AppPort = os.Getenv("APP_PORT")
	c.Environment = os.Getenv("NODE_ENV")
	c.RpcSecret = os.Getenv("RPC_SECRET")
}

func newConfig() fx.Option {
	return fx.Module("Config", fx.Provide(func() *Config {
		var config Config
		config.BuildFromEnv()
		return &config
	}))
}
